package androidx.appcompat.view.menu;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import java.util.ArrayList;
import o.bd;
import o.bj;
import o.bo.b;

@RestrictTo({d.LIBRARY_GROUP})
public class MenuAdapter extends BaseAdapter {
    public bd mAdapterMenu;
    private int mExpandedIndex = -1;
    private boolean mForceShowIcon;
    private final LayoutInflater mInflater;
    private final int mItemLayoutRes;
    private final boolean mOverflowOnly;

    public MenuAdapter(bd bdVar, LayoutInflater layoutInflater, boolean z, int i) {
        this.mOverflowOnly = z;
        this.mInflater = layoutInflater;
        this.mAdapterMenu = bdVar;
        this.mItemLayoutRes = i;
        findExpandedIndex();
    }

    public boolean getForceShowIcon() {
        return this.mForceShowIcon;
    }

    public void setForceShowIcon(boolean z) {
        this.mForceShowIcon = z;
    }

    public int getCount() {
        ArrayList ॱˊ = this.mOverflowOnly ? this.mAdapterMenu.ॱˊ() : this.mAdapterMenu.ʽ();
        if (this.mExpandedIndex < 0) {
            return ॱˊ.size();
        }
        return ॱˊ.size() - 1;
    }

    public bd getAdapterMenu() {
        return this.mAdapterMenu;
    }

    public bj getItem(int i) {
        ArrayList ॱˊ = this.mOverflowOnly ? this.mAdapterMenu.ॱˊ() : this.mAdapterMenu.ʽ();
        if (this.mExpandedIndex >= 0 && i >= this.mExpandedIndex) {
            i++;
        }
        return (bj) ॱˊ.get(i);
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        View inflate;
        boolean z;
        if (view == null) {
            inflate = this.mInflater.inflate(this.mItemLayoutRes, viewGroup, false);
        } else {
            inflate = view;
        }
        int groupId = getItem(i).getGroupId();
        int groupId2 = i + -1 >= 0 ? getItem(i - 1).getGroupId() : groupId;
        ListMenuItemView listMenuItemView = (ListMenuItemView) inflate;
        if (!this.mAdapterMenu.ॱ() || groupId == groupId2) {
            z = false;
        } else {
            z = true;
        }
        listMenuItemView.setGroupDividerEnabled(z);
        b bVar = (b) inflate;
        if (this.mForceShowIcon) {
            ((ListMenuItemView) inflate).setForceShowIcon(true);
        }
        bVar.ॱ(getItem(i), 0);
        return inflate;
    }

    void findExpandedIndex() {
        bj ॱˎ = this.mAdapterMenu.ॱˎ();
        if (ॱˎ != null) {
            ArrayList ॱˊ = this.mAdapterMenu.ॱˊ();
            int size = ॱˊ.size();
            for (int i = 0; i < size; i++) {
                if (((bj) ॱˊ.get(i)) == ॱˎ) {
                    this.mExpandedIndex = i;
                    return;
                }
            }
        }
        this.mExpandedIndex = -1;
    }

    public void notifyDataSetChanged() {
        findExpandedIndex();
        super.notifyDataSetChanged();
    }
}
